package com.fgbf.todo.MainClasses;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class LocItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	
	///////////////////////////////////////////////////////////////////////////////
	// INSTANCE DATA
	///////////////////////////////////////////////////////////////////////////////

	/**
	 * Arraylist of overlays
	 */
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	
	/**
	 * The context of the app
	 */
	private Context context;

	///////////////////////////////////////////////////////////////////////////////
	// CONSTRUCTORS
	///////////////////////////////////////////////////////////////////////////////

	/**
	 * Constructor
	 * @param defaultMarker
	 */
	public LocItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		// TODO Auto-generated constructor stub
	}
	//----------------------------------------------------------------------------

	/**
	 * Constructor
	 * @param defaultMarker
	 * @param context
	 */
	public LocItemizedOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  this.context = context;
	}
	//----------------------------------------------------------------------------

	
	///////////////////////////////////////////////////////////////////////////////
	// METHODS
	///////////////////////////////////////////////////////////////////////////////

	/**
	 * Adds an overlay
	 * @param overlay
	 */
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	//----------------------------------------------------------------------------

	/**
	 * Creates an item
	 */
	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return mOverlays.get(i);	
	}
	//----------------------------------------------------------------------------

	/**
	 * returns the size of the overlays
	 */
	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mOverlays.size();
	}
	//----------------------------------------------------------------------------

	/**
	 * responds to a tap event
	 */
	@Override
	protected boolean onTap(int index) {
	  OverlayItem item = mOverlays.get(index);
	  AlertDialog.Builder dialog = new AlertDialog.Builder(context);
	  dialog.setTitle(item.getTitle());
	  dialog.setMessage(item.getSnippet());
	  dialog.show();
	  return true;
	}
	//----------------------------------------------------------------------------


}
